package com.feng.nuike.huawei;

import java.util.*;

/**
 * @author feng
 * @decrition
 * @date 2022/2/170:09
 */
public class HJ25 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String s = scanner.nextLine();
            String[] split = s.split(" ");
            String[] strings = Arrays.copyOfRange(split, 1, split.length);
            String s1 = scanner.nextLine();
            String[] split1 = s1.split(" ");
            String[] strings1 = Arrays.copyOfRange(split1, 1, split1.length);
            Set<String> set = new TreeSet<String>(Arrays.asList(strings1));
            List<String> result = new ArrayList<>();
            List<Integer> index = new ArrayList<>();
            List<String> name = new ArrayList<>();
            Map<String, Integer> map = new LinkedHashMap<>();
            for (String str : set) {
                for (int i = 0; i < strings.length; i++) {
                    if (strings[i].contains(str)) {
                        Integer put = map.put(str, 1);
                        if (put != null) {
                            put++;
                            map.put(str, put);

                        }
                        index.add(i);
                        name.add(strings[i]);
                    }
                }
            }
            int i = 0;
            int j = 0;
            for (Map.Entry<String, Integer> stringIntegerEntry : map.entrySet()) {
                String key = stringIntegerEntry.getKey();
                Integer value = stringIntegerEntry.getValue();
                result.add(key);
                result.add(value.toString());
                i += Integer.valueOf(value);
                for (; j < i; j++) {
                    result.add(index.get(j).toString());
                    result.add(name.get(j));
                }
            }
            System.out.print(result.size());
            for (String s2 : result) {
                System.out.print(" " + s2);
            }
        }

    }

}
